package com.rockcent.mall.lib.domain;

import com.rockcent.common.domain.IDEntityMall;
import com.rockcent.mall.lib.domain.enumclass.UserInfoRegisterType;
import com.rockcent.mall.lib.domain.enumclass.UserInfoStatus;
import com.rockcent.mall.lib.domain.enumclass.UserBaseType;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;

/**
 * Created by oyhk on 16/7/13.
 */
@Entity
@Table(name = "auth_user")
@DynamicInsert(value = true)
@DynamicUpdate(value = true)
public class UserInfo extends IDEntityMall {

    @Column(columnDefinition = "varchar(255) comment '用户名'", unique = true)
    private String username;
    @Column(columnDefinition = "varchar(20) comment '手机'")
    private String mobile;
    @Column(columnDefinition = "varchar(50) comment '邮箱'")
    private String email;
    @Column(columnDefinition = "varchar(50) comment '真实姓名'")
    private String realName;
    @Column(name = "password_hash", columnDefinition = "varchar(255) comment '密码'")
    private String password;
    @Column(columnDefinition = "varchar(20) comment '状态(待激活:INACTIVE,已激活:ACTIVE,已停用:DISABLED)'")
    @Enumerated(EnumType.STRING)
    private UserInfoStatus status;
    @Column(columnDefinition = "varchar(20) comment '类型(基本:BASIC,派生:DERIVE)'")
    @Enumerated(EnumType.STRING)
    private UserBaseType type = UserBaseType.BASIC;
    @Column(columnDefinition = "varchar(20) comment '注册类型 (MOBILE(\"手机\"), EMAIL(\"邮件\"))'")
    @Enumerated(EnumType.STRING)
    private UserInfoRegisterType registerType;
    @Column(columnDefinition = "varchar(100) comment '用于密码加密的salt , 默认值当前时间'")
    private String salt;

    // 密码 md5 加密的key
    public static final String SSO_PASSWORD_ENCODE_KEY = "xc??vn()&^i@!#Y*!&@Tkl~~deh#*!ut@#!$ks√fhs213@1234vx>>>..';[]5938˜∫√ƒ45$@#&$T@&#$^!@#!*#$^*!^#*&^<>M";

    // 登录用户的session key
    public static final String LOGIN_USER = "loginUser";
    public static final String LOGIN_USERS = "loginUsers";
    public static final String LOGIN_MALL = "loginMall";
    public static final String ATTR_MALLID = "mallId";
    public static final String ATTR_USERNAME = "username";
    public static final String ATTR_MOBILE = "mobile";
    public static final String ATTR_EMAIL = "email";
    public static final String ATTR_THIS = "userInfo";
    public static final String CHECK_REALNAME_IS_NOT_NULL = "真是姓名不能为空";
    public static final String CHECK_USERNAME_IS_NOT_NULL = "用户名不能为空";
    public static final String CHECK_PASSWORD_IS_NOT_NULL = "密码不能为空";
    public static final String CHECK_SYSTEM_TYPE_IS_NOT_NULL = "类型不能为空";
    public static final String CHECK_REGISTER_CAPTCHA_IS_NOT_NULL = "注册验证码不能为空";
    public static final String REMIND_USERNAME_IS_REGISTERED = "用户名已被注册";
    public static final String REMIND_STATUS_EXCEPTION = "用户状态异常";
    public static final String REMIND_USERNAME_IS_NOT_EXIST = "用户名不存在";
    public static final String REMIND_PASSWORD_ERROR = "密码错误";
    public static final String REMIND_MALL_ID_EXCEPTION = "平台ID为空";
    public static final String REMIND_MALL_LOAD_EXCEPTION = "平台信息加载失败";
    public static final String VALUE_IS_NOT_NULL = "不能为空";

    // 用户手机注册 验证码key
    public static final String REDIS_REGISTER_MOBILE_CAPTCHA_USERNAME_PREFIX = "register_mobile_captcha_username_";
    // 用户邮件注册 邮件验证码key
    public static final String REDIS_REGISTER_EMAIL_CAPTCHA_USERNAME_PREFIX = "register_email_captcha_username_";
    // 用户忘记密码手机 验证码key
    public static final String REDIS_FORGOT_PASSWORD_MOBILE_CAPTCHA_USERNAME_PREFIX = "forgot_password_mobile_captcha_username_";
    // 用户忘记密码邮件 验证码key
    public static final String REDIS_FORGOT_PASSWORD_EMAIL_CAPTCHA_USERNAME_PREFIX = "forgot_password_email_captcha_username_";
    // 用户登录的cookie
    public static final String REDIS_USER_TOKEN_PREFIX = "user_token_";
    public static final String REDIS_MALL_INFO_PREFIX = "mall_info";
    public static final String REDIS_MALL_LOGIN_PREFIX = "mall_login_";
    public static final String REDIS_MERCHANT_LOGIN_PREFIX = "merchant_login_";

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public UserInfoStatus getStatus() {
        return status;
    }

    public void setStatus(UserInfoStatus status) {
        this.status = status;
    }

    public UserBaseType getType() {
        return type;
    }

    public void setType(UserBaseType type) {
        this.type = type;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public UserInfoRegisterType getRegisterType() {
        return registerType;
    }

    public void setRegisterType(UserInfoRegisterType registerType) {
        this.registerType = registerType;
    }

    @Override
    public String
    toString() {
        return "UserInfo{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", dateCreated=" + dateCreated +
                ", mobile='" + mobile + '\'' +
                ", email='" + email + '\'' +
                ", lastUpdated=" + lastUpdated +
                ", realName='" + realName + '\'' +
                ", isDelete=" + isDelete +
                ", password='" + password + '\'' +
                ", version=" + version +
                ", status=" + status +
                ", type=" + type +
                ", registerType=" + registerType +
                ", salt='" + salt + '\'' +
                '}';
    }
}
